#include "JSValueWrapper.h"
#include "RenderBufferWrapper.h"
#include "ResourceInterceptorWrapper.h"
#include "WebCoreWrapper.h"
#include "WebViewWrapper.h"
#include "WebKeyboardEventWrapper.h"
#include "WebViewListenerWrapper.h"

namespace AwesomiumDotNet
{
	BeginLoadingEventArgs::BeginLoadingEventArgs(AwesomiumDotNet::WebView^ webView,
		String^ url, String^ frameName,	int statusCode, String^ mimeType)
	{
		this->WebView = webView;
		this->Url = url;
		this->FrameName = frameName;
		this->StatusCode = statusCode;
		this->MimeType = mimeType;
	}

	BeginNavigationEventArgs::BeginNavigationEventArgs(AwesomiumDotNet::WebView^ webView,
		String^ url, String^ frameName)
	{
		this->WebView = webView;
		this->Url = url;
		this->FrameName = frameName;
	}

	CallbackEventArgs::CallbackEventArgs(AwesomiumDotNet::WebView^ webView,
		String^ objectName, String^ callbackName, Collection<AwesomiumDotNet::JSValue^>^ args)
	{
		this->WebView = webView;
		this->ObjectName = objectName;
		this->CallbackName = callbackName;
		this->_args = args;
	}

	ChangeCursorEventArgs::ChangeCursorEventArgs(AwesomiumDotNet::WebView^ webView,
		AwesomiumDotNet::CursorType cursorType)
	{
		this->WebView = webView;
		this->CursorType = cursorType;
	}

	Windows::Forms::Cursor^ ChangeCursorEventArgs::Cursor::get()
	{
		switch(CursorType)
		{
		case CursorPointer:
			return Cursors::Arrow;
		case CursorCross:
			return Cursors::Cross;
		case CursorHand:
			return Cursors::Hand;
		case CursorIBeam:
			return Cursors::IBeam;
		case CursorWait:
			return Cursors::WaitCursor;
		case CursorHelp:
			return Cursors::Help;
		case CursorEastResize:
			return Cursors::SizeWE;
		case CursorNorthResize:
			return Cursors::SizeNS;
		case CursorNorthEastResize:
			return Cursors::SizeNESW;
		case CursorNorthWestResize:
			return Cursors::SizeNWSE;
		case CursorSouthResize:
			return Cursors::SizeNS;
		case CursorSouthEastResize:
			return Cursors::SizeNWSE;
		case CursorSouthWestResize:
			return Cursors::SizeNESW;
		case CursorWestResize:
			return Cursors::SizeWE;
		case CursorNorthSouthResize:
			return Cursors::SizeNS;
		case CursorEastWestResize:
			return Cursors::SizeWE;
		case CursorNorthEastSouthWestResize:
			return Cursors::SizeNESW;
		case CursorNorthWestSouthEastResize:
			return Cursors::SizeNWSE;
		case CursorColumnResize:
			return Cursors::SizeWE;
		case CursorRowResize:
			return Cursors::SizeNS;
		case CursorMiddlePanning:
			break;
		case CursorEastPanning:
			return Cursors::PanEast;
		case CursorNorthPanning:
			return Cursors::PanNorth;
		case CursorNorthEastPanning:
			return Cursors::PanNE;
		case CursorNorthWestPanning:
			return Cursors::PanNW;
		case CursorSouthPanning:
			return Cursors::PanSouth;
		case CursorSouthEastPanning:
			return Cursors::PanSE;
		case CursorSouthWestPanning:
			return Cursors::PanSW;
		case CursorWestPanning:
			return Cursors::PanWest;
		case CursorMove:
			return Cursors::SizeAll;
		case CursorVerticalText:
			return Cursors::IBeam;
		case CursorCell:
			break;
		case CursorContextMenu:
			break;
		case CursorAlias:
			break;
		case CursorProgress:
			return Cursors::AppStarting;
		case CursorNoDrop:
			return Cursors::No;
		case CursorCopy:
			break;
		case CursorNone:
			break;
		case CursorNotAllowed:
			return Cursors::No;
		case CursorZoomIn:
			break;
		case CursorZoomOut:
			break;
		case CursorCustom:
			break;
		}
		return Cursors::Default;
	}

	ChangeKeyboardFocusEventArgs::ChangeKeyboardFocusEventArgs(AwesomiumDotNet::WebView^ webView,
		bool isFocused)
	{
		this->WebView = webView;
		this->IsFocused = isFocused;
	}

	ChangeTargetUrlEventArgs::ChangeTargetUrlEventArgs(AwesomiumDotNet::WebView^ webView,
		String^ url)
	{
		this->WebView = webView;
		this->Url = url;
	}

	ChangeTooltipEventArgs::ChangeTooltipEventArgs(AwesomiumDotNet::WebView^ webView,
		String^ tooltip)
	{
		this->WebView = webView;
		this->Tooltip = tooltip;
	}

	FinishLoadingEventArgs::FinishLoadingEventArgs(AwesomiumDotNet::WebView^ webView) {
		this->WebView = webView;
	}

	ReceiveTitleEventArgs::ReceiveTitleEventArgs(AwesomiumDotNet::WebView^ webView,
		String^ title, String^ frameName)
	{
		this->WebView = webView;
		this->Title = title;
		this->FrameName = frameName;
	}

	OpenExternalLinkEventArgs::OpenExternalLinkEventArgs(AwesomiumDotNet::WebView^ webView,
		String^ url, String^ source)
	{
		this->WebView = webView;
		this->Url = url;
		this->Source = source;
	}

	RequestDownloadEventArgs::RequestDownloadEventArgs(AwesomiumDotNet::WebView^ webView,
		String^ url)
	{
		this->WebView = webView;
		this->Url = url;
	}

	WebViewCrashedEventArgs::WebViewCrashedEventArgs(AwesomiumDotNet::WebView^ webView) {
		this->WebView = webView;
	}

	PluginCrashedEventArgs::PluginCrashedEventArgs(AwesomiumDotNet::WebView^ webView,
		String^ pluginName)
	{
		this->WebView = webView;
		this->PluginName = pluginName;
	}

	RequestMoveEventArgs::RequestMoveEventArgs(AwesomiumDotNet::WebView^ webView,
		int x, int y)
	{
		this->WebView = webView;
		this->X = x;
		this->Y = y;
	}

	GetPageContentsEventArgs::GetPageContentsEventArgs(AwesomiumDotNet::WebView^ webView,
		String^ url, String^ contents)
	{
		this->WebView = webView;
		this->Url = url;
		this->Contents = contents;
	}

	DomReadyEventArgs::DomReadyEventArgs(AwesomiumDotNet::WebView^ webView) {
		this->WebView = webView;
	}

	GetScrollDataEventArgs::GetScrollDataEventArgs(AwesomiumDotNet::WebView^ webView,
		int contentWidth, int contentHeight, int preferredWidth, int scrollX, int scrollY)
	{
		this->WebView = webView;
		this->ContentWidth = contentWidth;
		this->ContentHeight = contentHeight;
		this->PreferredWidth = preferredWidth;
		this->ScrollX = scrollX;
		this->ScrollY = scrollY;
	}

	RequestFileChooserEventArgs::RequestFileChooserEventArgs(AwesomiumDotNet::WebView^ webView,
		bool selectMultipleFiles, String^ title, String^ defaultPath)
	{
		this->WebView = webView;
		this->Title = title;
		this->DefaultPath = defaultPath;
	}

	JavascriptConsoleMessageEventArgs::JavascriptConsoleMessageEventArgs(AwesomiumDotNet::WebView^ webView,
		String^ message, int lineNumber, String^ source)
	{
		this->WebView = webView;
		this->Message = message;
		this->LineNumber = lineNumber;
		this->Source = source;
	}


	void WebView::OnBeginLoading(BeginLoadingEventArgs^ args)
	{
		BeginLoading(this, args);
	}

	void WebView::OnBeginNavigation(BeginNavigationEventArgs^ args)
	{
		BeginNavigation(this, args);
	}

	void WebView::OnCallback(CallbackEventArgs^ args)
	{
		Callback(this, args);
	}

	void WebView::OnChangeCursor(ChangeCursorEventArgs^ args)
	{
		ChangeCursor(this, args);
	}

	void WebView::OnChangeKeyboardFocus(ChangeKeyboardFocusEventArgs^ args)
	{
		ChangeKeyboardFocus(this, args);
	}

	void WebView::OnChangeTargetUrl(ChangeTargetUrlEventArgs^ args)
	{
		ChangeTargetUrl(this, args);
	}

	void WebView::OnChangeTooltip(ChangeTooltipEventArgs^ args)
	{
		ChangeTooltip(this, args);
	}

	void WebView::OnFinishLoading(FinishLoadingEventArgs^ args)
	{
		FinishLoading(this, args);
	}

	void WebView::OnOpenExternalLink(OpenExternalLinkEventArgs^ args)
	{
		OpenExternalLink(this, args);
	}

	void WebView::OnReceiveTitle(ReceiveTitleEventArgs^ args)
	{
		ReceiveTitle(this, args);
	}

	void WebView::OnWebViewCrashed(WebViewCrashedEventArgs^ args)
	{
		WebViewCrashed(this, args);
	}

	void WebView::OnPluginCrashed(PluginCrashedEventArgs^ args)
	{
		PluginCrashed(this, args);
	}

	void WebView::OnRequestMove(RequestMoveEventArgs^ args)
	{
		RequestMove(this, args);
	}

	void WebView::OnGetPageContents(GetPageContentsEventArgs^ args)
	{
		GetPageContents(this, args);
	}

	void WebView::OnDomReady(DomReadyEventArgs^ args)
	{
		DomReady(this, args);
	}

	void WebView::OnRequestDownload(RequestDownloadEventArgs^ args)
	{
		RequestDownload(this, args);
	}

	void WebView::OnRequestFileChooser(RequestFileChooserEventArgs^ args)
	{
		RequestFileChooser(this, args);
	}

	void WebView::OnGetScrollData(GetScrollDataEventArgs^ args)
	{
		GetScrollData(this, args);
	}

	void WebView::OnJavascriptConsoleMessage(JavascriptConsoleMessageEventArgs^ args)
	{
		JavascriptConsoleMessage(this, args);
	}


	WebView::WebView (WebCore^ webCore, int width, int height)
	{
		markedDestroyed = false;
		this->webView = webCore->getCore()->createWebView(width, height);
		this->webView->setListener(new WebViewListenerWrapper(this));
	}

	WebView::~WebView()
	{
		this->!WebView();
	}

	WebView::!WebView()
	{
		if (IsDisposed)
			return;

		WebCore::webViewList->Remove(this);

		webView->setResourceInterceptor(0);
		webView->setListener(0);
		if (markedDestroyed == false)
			webView->destroy();
		webView = 0;
	}

	bool WebView::IsDisposed::get()
	{
		return (webView == 0);
	}

	bool WebView::IsResizing::get()
	{
		return webView->isResizing();
	}

	ResourceInterceptor^ WebView::ResourceInterceptor::get()
	{
		return resourceInterceptor;
	}

	void WebView::ResourceInterceptor::set(AwesomiumDotNet::ResourceInterceptor^ value)
	{
		resourceInterceptor = value;
		if (value == nullptr)
		{
			webView->setResourceInterceptor(0);
		}
		else
		{
			value->getNative()->setOwner(this);
			webView->setResourceInterceptor(value->getNative());
		}
	}

	void WebView::Destroy()
	{
		webView->destroy();
		markedDestroyed = true;

		// Don't call the destructor here, we'll do that after an Update call to WebCore.
	}


	void WebView::Focus()
	{
		webView->focus();
	}
	void WebView::Unfocus()
	{
		webView->unfocus();
	}

	void WebView::Copy()
	{
		webView->copy();
	}

	void WebView::Cut()
	{
		webView->cut();
	}

	void WebView::Paste()
	{
		webView->paste();
	}

	void WebView::SelectAll()
	{
		webView->selectAll();
	}

	void WebView::SetZoom(int zoomPercent)
	{
		webView->setZoom(zoomPercent);
	}

	void WebView::ResetZoom()
	{
		webView->resetZoom();
	}

	bool WebView::Resize (int width, int height, bool waitForRepaint, int repaintTimeoutMs)
	{
		return webView->resize(width, height, waitForRepaint, repaintTimeoutMs);
	}

	bool WebView::Resize (int width, int height, bool waitForRepaint)
	{
		return webView->resize(width, height, waitForRepaint);
	}

	bool WebView::Resize (int width, int height)
	{
		return webView->resize(width, height);
	}

	void WebView::InjectMouseMove (int x, int y)
	{
		webView->injectMouseMove(x, y);
	}

	void WebView::InjectMouseMove (Point position)
	{
		webView->injectMouseMove(position.X, position.Y);
	}

	void WebView::InjectMouseDown (MouseButton button)
	{
		webView->injectMouseDown((Awesomium::MouseButton)button);
	}

	void WebView::InjectMouseDown (MouseButtons button)
	{
		if (button == MouseButtons::Left)
			webView->injectMouseDown(Awesomium::LEFT_MOUSE_BTN);
		else if (button == MouseButtons::Right)
			webView->injectMouseDown(Awesomium::RIGHT_MOUSE_BTN);
		else if (button == MouseButtons::Middle)
			webView->injectMouseDown(Awesomium::MIDDLE_MOUSE_BTN);
	}

	void WebView::InjectMouseUp (MouseButton button)
	{
		webView->injectMouseUp((Awesomium::MouseButton)button);
	}

	void WebView::InjectMouseUp (MouseButtons button)
	{
		if (button == MouseButtons::Left)
			webView->injectMouseUp(Awesomium::LEFT_MOUSE_BTN);
		else if (button == MouseButtons::Right)
			webView->injectMouseUp(Awesomium::RIGHT_MOUSE_BTN);
		else if (button == MouseButtons::Middle)
			webView->injectMouseUp(Awesomium::MIDDLE_MOUSE_BTN);
	}

	void WebView::InjectMouseWheel (int scrollAmountVert)
	{
		webView->injectMouseWheel(scrollAmountVert);
	}

	void WebView::InjectMouseWheel (int scrollAmountVert, int scrollAmountHorz)
	{
		webView->injectMouseWheel(scrollAmountVert, scrollAmountHorz);
	}

	void WebView::InjectKeyboardEvent (WebKeyboardEvent^ keyboardEvent)
	{
		webView->injectKeyboardEvent(keyboardEvent->ToNative());
	}

	void WebView::InjectKeyboardEvent (Message message)
	{
		webView->injectKeyboardEvent(
			Awesomium::WebKeyboardEvent(message.Msg,
			(WPARAM)message.WParam.ToPointer(),
			(LPARAM)message.LParam.ToPointer())
			);
	}

	void WebView::LoadUrl (Uri^ url)
	{
		LoadUrl(url->ToString());
	}

	void WebView::LoadUrl(String^ url)
	{
		wchar_t* urlTemp = MarshalStringW(url);
		webView->loadURL(urlTemp);
		FreeUnmanagedString(urlTemp);
	}

	void WebView::LoadUrl (Uri^ url, String^ frameName)
	{
		LoadUrl(url->ToString(), frameName);
	}

	void WebView::LoadUrl (String^ url, String^ frameName)
	{
		wchar_t* urlTemp = MarshalStringW(url);
		wchar_t* frameNameTemp = MarshalStringW(frameName);

		webView->loadURL(urlTemp, frameNameTemp);

		FreeUnmanagedString(frameNameTemp);
		FreeUnmanagedString(urlTemp);
	}

	void WebView::LoadUrl (Uri^ url, String^ frameName, String^ username, String^ password)
	{
		LoadUrl(url->ToString(), frameName, username, password);
	}

	void WebView::LoadUrl (String^ url, String^ frameName, String^ username, String^ password)
	{
		wchar_t* urlTemp = MarshalStringW(url);
		wchar_t* frameNameTemp = MarshalStringW(frameName);
		char* usernameTemp = MarshalString(username);
		char* passwordTemp = MarshalString(password);

		webView->loadURL(urlTemp, frameNameTemp,
			usernameTemp, passwordTemp);

		FreeUnmanagedString(passwordTemp);
		FreeUnmanagedString(usernameTemp);
		FreeUnmanagedString(frameNameTemp);
		FreeUnmanagedString(urlTemp);
	}

	void WebView::LoadHtml (String^ html)
	{
		wchar_t* htmlTemp = MarshalStringW(html);
		webView->loadHTML(htmlTemp);
		FreeUnmanagedString(htmlTemp);
	}

	void WebView::LoadHtml (String^ html, String^ frameName)
	{
		wchar_t* htmlTemp = MarshalStringW(html);
		wchar_t* frameNameTemp = MarshalStringW(frameName);

		webView->loadHTML(htmlTemp, frameNameTemp);

		FreeUnmanagedString(frameNameTemp);
		FreeUnmanagedString(htmlTemp);
	}

	void WebView::LoadFile (String^ file)
	{
		char* fileTemp = MarshalString(file);
		webView->loadFile(fileTemp);
		FreeUnmanagedString(fileTemp);
	}

	void WebView::LoadFile (String^ file, String^ frameName)
	{
		char* fileTemp = MarshalString(file);
		wchar_t* frameNameTemp = MarshalStringW(frameName);

		webView->loadFile(fileTemp, frameNameTemp);

		FreeUnmanagedString(frameNameTemp);
		FreeUnmanagedString(fileTemp);
	}

	void WebView::SetTransparent (bool isTransparent)
	{
		webView->setTransparent(isTransparent);
	}

	AwesomiumDotNet::RenderBuffer^ WebView::Render ()
	{
		const Awesomium::RenderBuffer* buffer = webView->render();
		if (buffer == NULL)
			return nullptr;
		return gcnew AwesomiumDotNet::RenderBuffer(buffer);
	}

	void WebView::PauseRendering()
	{
		webView->pauseRendering();
	}

	void WebView::ResumeRendering()
	{
		webView->resumeRendering();
	}

	bool WebView::IsDirty::get()
	{
		return webView->isDirty();
	}

	bool WebView::IsLoadingPage::get()
	{
		return webView->isLoadingPage();
	}

	System::Drawing::Rectangle^ WebView::DirtyBounds::get()
	{
		Rect r = webView->getDirtyBounds();
		return gcnew System::Drawing::Rectangle(r.x, r.y, r.width, r.height);
	}

	void WebView::GoToHistoryOffset (int offset)
	{
		webView->goToHistoryOffset(offset);
	}

	void WebView::Stop()
	{
		webView->stop();
	}

	void WebView::Reload()
	{
		webView->reload();
	}

	void WebView::ExecuteJavaScript (String^ javaScript)
	{
		wchar_t* javaScriptTemp = MarshalStringW(javaScript);
		webView->executeJavascript(javaScriptTemp);
		FreeUnmanagedString(javaScriptTemp);
	}

	void WebView::ExecuteJavaScript (String^ javaScript, String^ frameName)
	{
		wchar_t* javaScriptTemp = MarshalStringW(javaScript);
		wchar_t* frameNameTemp = MarshalStringW(frameName);

		webView->executeJavascript(javaScriptTemp, frameNameTemp);

		FreeUnmanagedString(frameNameTemp);
		FreeUnmanagedString(javaScriptTemp);
	}

	FutureJSValue^ WebView::ExecuteJavaScriptWithResult (String^ javaScript)
	{
		wchar_t* javaScriptTemp = MarshalStringW(javaScript);

		Awesomium::FutureJSValue resultTemp =
			webView->executeJavascriptWithResult(javaScriptTemp);
		FutureJSValue^ result = gcnew FutureJSValue(resultTemp);

		FreeUnmanagedString(javaScriptTemp);

		return result;
	}

	FutureJSValue^ WebView::ExecuteJavaScriptWithResult (String^ javaScript, String^ frameName)
	{
		wchar_t* javaScriptTemp = MarshalStringW(javaScript);
		wchar_t* frameNameTemp = MarshalStringW(frameName);

		Awesomium::FutureJSValue resultTemp = webView->executeJavascriptWithResult(
			javaScriptTemp, frameNameTemp);
		FutureJSValue^ result = gcnew FutureJSValue(resultTemp);

		FreeUnmanagedString(frameNameTemp);
		FreeUnmanagedString(javaScriptTemp);

		return result;
	}

	void WebView::CreateObject (String^ objectName)
	{
		wchar_t* objectNameTemp = MarshalStringW(objectName);
		webView->createObject(objectNameTemp);
		FreeUnmanagedString(objectNameTemp);
	}

	void WebView::DestroyObject (String^ objectName)
	{
		wchar_t* objectNameTemp = MarshalStringW(objectName);
		webView->destroyObject(objectNameTemp);
		FreeUnmanagedString(objectNameTemp);
	}

	void WebView::CallJavaScriptFunction (String^ objectName, String^ functionName, IEnumerable<JSValue^>^ args)
	{
		wchar_t* objectNameTemp = MarshalStringW(objectName);
		wchar_t* functionNameTemp = MarshalStringW(functionName);

		Awesomium::JSArguments nativeArgs = Awesomium::JSArguments();
		if (args != nullptr)
		{
			for each (JSValue^ arg in args)
				nativeArgs.push_back(arg->ToNative());
		}

		webView->callJavascriptFunction(
			objectNameTemp, functionNameTemp, nativeArgs);

		FreeUnmanagedString(functionNameTemp);
		FreeUnmanagedString(objectNameTemp);
	}

	void WebView::CallJavaScriptFunction (String^ objectName, String^ functionName,
		IEnumerable<JSValue^>^ args, String^ frameName)
	{
		wchar_t* objectNameTemp = MarshalStringW(objectName);
		wchar_t* functionNameTemp = MarshalStringW(functionName);
		wchar_t* frameNameTemp = MarshalStringW(frameName);

		Awesomium::JSArguments nativeArgs = Awesomium::JSArguments();
		if (args != nullptr)
		{
			for each (JSValue^ arg in args)
				nativeArgs.push_back(arg->ToNative());
		}

		webView->callJavascriptFunction(objectNameTemp,
			functionNameTemp, nativeArgs, frameNameTemp);

		FreeUnmanagedString(frameNameTemp);
		FreeUnmanagedString(functionNameTemp);
		FreeUnmanagedString(objectNameTemp);
	}

	void WebView::SetObjectProperty (String^ objectName, String^ propName, JSValue^ value)
	{
		wchar_t* objectNameTemp = MarshalStringW(objectName);
		wchar_t* propNameTemp = MarshalStringW(propName);

		Awesomium::JSValue nativevalue = value->ToNative();
		webView->setObjectProperty(objectNameTemp, propNameTemp, nativevalue);

		FreeUnmanagedString(propNameTemp);
		FreeUnmanagedString(objectNameTemp);
	}

	void WebView::SetObjectCallback (String^ objectName, String^ callbackName)
	{
		wchar_t* objectNameTemp = MarshalStringW(objectName);
		wchar_t* callbackNameTemp = MarshalStringW(callbackName);

		webView->setObjectCallback(objectNameTemp, callbackNameTemp);

		FreeUnmanagedString(callbackNameTemp);
		FreeUnmanagedString(objectNameTemp);
	}

	void WebView::SetUrlFilteringMode (UrlFilteringMode mode)
	{
		webView->setURLFilteringMode((Awesomium::URLFilteringMode)mode);
	}

	void WebView::AddUrlFilter (String^ filter)
	{
		wchar_t* filterTemp = MarshalStringW(filter);
		webView->addURLFilter(filterTemp);
		FreeUnmanagedString(filterTemp);
	}

	void WebView::ClearAllUrlFilters()
	{
		webView->clearAllURLFilters();
	}

	void WebView::SetHeaderDefinition (String^ name, IDictionary<String^, String^>^ definition)
	{
		char* nameTemp = MarshalString(name);

		Awesomium::HeaderDefinition nativeDefinition;
		for each(KeyValuePair<String^, String^> value in definition)
		{
			char* keyTemp = MarshalString(value.Key);
			char* valueTemp = MarshalString(value.Value);

			nativeDefinition.insert(
				std::pair<std::string, std::string>(keyTemp, valueTemp));

			//FreeUnmanagedString(keyTemp);
			//FreeUnmanagedString(valueTemp);
		}

		webView->setHeaderDefinition(nameTemp, nativeDefinition);

		FreeUnmanagedString(nameTemp);
	}

	void WebView::AddHeaderRewriteRule (String^ rule, String^ name)
	{
		wchar_t* ruleTemp = MarshalStringW(rule);
		char* nameTemp = MarshalString(name);

		webView->addHeaderRewriteRule(ruleTemp, nameTemp);

		FreeUnmanagedString(ruleTemp);
		FreeUnmanagedString(nameTemp);
	}

	void WebView::RemoveHeaderRewriteRule (String^ rule)
	{
		wchar_t* ruleTemp = MarshalStringW(rule);
		webView->removeHeaderRewriteRule(ruleTemp);
		FreeUnmanagedString(ruleTemp);
	}

	void WebView::RemoveHeaderRewriteRulesByDefinitionName (String^ name)
	{
		char* nameTemp = MarshalString(name);
		webView->removeHeaderRewriteRulesByDefinitionName(nameTemp);
		FreeUnmanagedString(nameTemp);
	}

	void WebView::ChooseFile (String^ filePath)
	{
		wchar_t* filePathTemp = MarshalStringW(filePath);
		webView->chooseFile(filePathTemp);
		FreeUnmanagedString(filePathTemp);
	}

	void WebView::ChooseMultipleFiles (IEnumerable<String^>^ filePaths)
	{
		std::vector<std::wstring> filePathsTemp;

		for each (String^ filePath in filePaths)
			filePathsTemp.push_back(MarshalStringW(filePath));
		webView->chooseMultipleFiles(filePathsTemp);

		//std::vector<std::wstring>::iterator it = filePathsTemp.begin();
		//for(; it < filePathsTemp.end(); it++)
		//	FreeUnmanagedString(*it);
	}

	void WebView::Print()
	{
		webView->print();
	}

	void WebView::RequestScrollData (String^ frameName)
	{
		wchar_t* frameNameTemp = MarshalStringW(frameName);
		webView->requestScrollData(frameNameTemp);
		FreeUnmanagedString(frameNameTemp);
	}

	void WebView::RequestScrollData()
	{
		webView->requestScrollData();
	}
}
